package cate.game.res.drop;

import cate.common.annotation.SplitParse;
import cate.common.util.SplitParser;
import easy.java.dev.note.NoteClass;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@NoteClass(value = "挂机掉落分组配置")
public class HangDropGroupConfig {

    public List<Item> list = new ArrayList<>();

    public void parse(String config) {
        if (StringUtils.isBlank(config)) {
            return;
        }
        list = SplitParser.parse(Item.class, config);
        list.removeIf(a -> a.weight <= 0);
    }

    public static class Item {
        @SplitParse(order = 0, defaultValue = "10003", note = "挂机掉落分组")
        public int group;

        @SplitParse(order = 1, defaultValue = "100", note = "掉落概率，100则百分百掉落")
        public double weight;
    }

    public List<Integer> randomGroup() {
        List<Integer> result = new ArrayList<>();
        for (Item item : list) {
            if (item.weight >= (int) (100 * Math.random())) {
                result.add(item.group);
            }
        }
        return result;
    }
}
